package com.example.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Toast;

import com.example.myapplication.adapter.MyAdapter;

public class MainActivity extends AppCompatActivity {

    private ListView listView;
    private String[] username;
    private String[] score;
    private int[] headImg;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initData();
        initEvent();
    }
    private void initView(){
        listView = findViewById(R.id.listview);
    }
    private void initData(){
        username = new String[]{"小明","小黑","小白","小赵"};
        score = new String[]{"90","80","85","100"};
        listView.setAdapter(new MyAdapter(MainActivity.this, username, score,headImg));
        headImg = new int[]{};
    }
    private void initEvent(){
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Toast.makeText(MainActivity.this,username[position]+":"+score[position],Toast.LENGTH_SHORT).show();
            }
        });
    }
}